package net.sx.minemodule.mvp.bean;

import android.os.Parcel;
import android.os.Parcelable;

import com.kedll.library.adapter.MultiTypeAdapter;
import com.kedll.library.mvp.BaseItem;
import com.kedll.library.mvp.BaseModel;

import net.sx.minemodule.mvp.item.OrderItem;
import net.sx.minemodule.mvp.item.OrderItems;

import java.util.List;

/**
 * @author 11470
 */
public class OrderBean extends BaseModel<BaseItem> implements Parcelable {

    /**
     * orderId : 2
     * orderSn : 201809150102000002
     * payAmount : 16378
     * totalAmount : 18732
     * status : 1
     * parentId : 0
     * orderProducts : [{"id":1,"productId":26,"pic":"http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/images/20180607/5ac1bf58Ndefaac16.jpg","productName":"华为 HUAWEI P20","num":1,"salePrice":37,"attrs":[{"name":"测试","value":"16GB"}]}]
     */

    private int orderId;
    private String orderSn;
    private int payAmount;
    private float totalAmount;
    private int status;
    private int parentId;
    private String shopImg;
    private String stopName;
    private List<GoodsBean> orderProducts;

    public OrderBean() {
    }

    @Override
    public BaseItem<OrderBean> createItem(MultiTypeAdapter adapter) {
        if ((getOrderProducts() == null || getOrderProducts().isEmpty()) || getOrderProducts().size() < 2) {
            //单个商品 item
            return new OrderItem(this);
        } else {
            //多个商品 item
            return new OrderItems(this);
        }
    }


    /**
     * 订单状态：
     * -1->已取消 ;
     * 0->待付款；
     * 1->待发货；
     * 2->已发货(待收货)；
     * 3->已完成；
     * 4->已关闭；
     * 5->无效订单;
     * 6->维权中;
     * 7->完成交易;
     * 8->已完成退款;
     * 9->已完成退款退货
     *
     * @return
     */
    public String getOrderType() {
        switch (getStatus()) {
            case 0:
                return "待支付";
            case 1:
                return "已支付";
            case 2:
                return "已发货";
            case 3:
                return "已签收";
            case 4:
                return "已关闭";
            case 5:
                return "无效订单";
            case 6:
                return "维权中";
            case 8:
            case 9:
                return "退款成功";
            default:
                return "";
        }
    }

    public int getOrderId() {
        return orderId;
    }

    public void setOrderId(int orderId) {
        this.orderId = orderId;
    }

    public String getOrderSn() {
        return orderSn;
    }

    public void setOrderSn(String orderSn) {
        this.orderSn = orderSn;
    }

    public int getPayAmount() {
        return payAmount;
    }

    public void setPayAmount(int payAmount) {
        this.payAmount = payAmount;
    }

    public float getTotalAmount() {
        return totalAmount;
    }

    public void setTotalAmount(int totalAmount) {
        this.totalAmount = totalAmount;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getShopImg() {
        return shopImg;
    }

    public void setShopImg(String shopImg) {
        this.shopImg = shopImg;
    }

    public String getStopName() {
        return stopName;
    }

    public void setStopName(String stopName) {
        this.stopName = stopName;
    }

    public int getParentId() {
        return parentId;
    }

    public void setParentId(int parentId) {
        this.parentId = parentId;
    }

    public List<GoodsBean> getOrderProducts() {
        return orderProducts;
    }

    public void setOrderProducts(List<GoodsBean> orderProducts) {
        this.orderProducts = orderProducts;
    }

    protected OrderBean(Parcel in) {
        orderId = in.readInt();
        orderSn = in.readString();
        payAmount = in.readInt();
        totalAmount = in.readInt();
        status = in.readInt();
        parentId = in.readInt();
        orderProducts = in.createTypedArrayList(GoodsBean.CREATOR);
    }

    public int getGoodsCount() {
        if (getOrderProducts() == null) {
            return 0;
        }
        int num = 0;
        for (GoodsBean item : getOrderProducts()) {
            num += item.getNum();
        }

        return num;
    }

    public static final Creator<OrderBean> CREATOR = new Creator<OrderBean>() {
        @Override
        public OrderBean createFromParcel(Parcel in) {
            return new OrderBean(in);
        }

        @Override
        public OrderBean[] newArray(int size) {
            return new OrderBean[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(orderId);
        dest.writeString(orderSn);
        dest.writeString(shopImg);
        dest.writeString(stopName);
        dest.writeInt(payAmount);
        dest.writeFloat(totalAmount);
        dest.writeInt(status);
        dest.writeInt(parentId);
        dest.writeTypedList(orderProducts);
    }


}
